package com.yonyou.crm.sys.dynamic.builder;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;

public class DynamicContentBuilder {
	List<Field> fields ;
	
	public DynamicContentBuilder() {
		fields = new ArrayList<Field>();
	}
	
	public DynamicContentBuilder(List<Field> fields) {
		super();
		this.fields = fields;
	}

	public DynamicContentBuilder append(String token) {
		fields.add(new Field(token));
		return this;
	}
	public DynamicContentBuilder append(Field field) {
		fields.add(field);
		return this;
	}
	
	public String toJSON() {
		JSONArray array = new JSONArray();
		for(int i=0,len=fields.size();i<len;i++) {
			array.add(fields.get(i).toJSONObject());
		}
		return array.toString();
	}
}
